// 导入用户集合
const { Category } = require('../../../model/category');
const { ChildCategory } = require('../../../model/childCategory');

module.exports = (req, res) => {
  const { id } = req.body
  const callback = (err, row) => {
    console.log(row)
    if (row.n === 0) {
      // 下级分类
      ChildCategory.updateOne({_id: id}, req.body, callback)
    } else if(!err) {
      res.json({
        message: '更新成功!'
      })
    } else {
      res.status(403)
      res.json({
        log: err,
        message: '更新失败！'
      })
    }
  }
  Category.updateOne({_id: id}, req.body, callback)
}